columnview: Make resize cursors reliable
authorMatthias Clasen <mclasen@redhat.com>
Mon, 19 Oct 2020 12:28:24 +0000 (08:28 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 19 Oct 2020 12:30:22 +0000 (08:30 -0400)
Ensure that the column resize cursor stays in place
for the duration of the resize drag. This is a bit
annoying, since the implicit grab can end up on the
header of a different column from the one we are
resizing, so just set the cursor on all column headers.

gtk/gtkcolumnview.c

index 66ff4c4d96cacf4fdc29de7df9986a764ac74f7f..eea3bb25718e7fb90b8fcc5cf428e40ff88e8355 100644 (file)
@@ -895,6 +895,25 @@ header = gtk_column_view_column_get_header (column);
   return graphene_rect_contains_point (&rect, &(graphene_point_t) { x, y});
 }
 
+static void
+set_resize_cursor (GtkColumnView *self,
+                   gboolean       set)
+{
+  int i, n;
+
+  n = g_list_model_get_n_items (G_LIST_MODEL (self->columns));
+  for (i = 0; i < n; i++)
+    {
+      GtkColumnViewColumn *column = g_list_model_get_item (G_LIST_MODEL (self->columns), i);
+      GtkWidget *header = gtk_column_view_column_get_header (column);
+      if (set)
+        gtk_widget_set_cursor_from_name (header, "col-resize");
+      else
+        gtk_widget_set_cursor (header, NULL);
+      g_object_unref (column);
+    }
+}
+
 static void
 header_drag_begin (GtkGestureDrag *gesture,
                    double          start_x,
@@ -933,7 +952,10 @@ header_drag_begin (GtkGestureDrag *gesture,
           self->drag_x = start_x - size;
           self->in_column_resize = TRUE;
 
+          set_resize_cursor (self, TRUE);
+
           g_object_unref (column);
+
           break;
         }
     }
@@ -981,6 +1003,7 @@ header_drag_end (GtkGestureDrag *gesture,
 
   if (self->in_column_resize)
     {
+      set_resize_cursor (self, FALSE);
       self->in_column_resize = FALSE;
     }
   else if (self->in_column_reorder)
@@ -1117,6 +1140,9 @@ header_motion (GtkEventControllerMotion *controller,
   gboolean cursor_set = FALSE;
   int i, n;
 
+  if (self->in_column_resize)
+    return;
+
   n = g_list_model_get_n_items (G_LIST_MODEL (self->columns));
   for (i = 0; i < n; i++)
     {